昨天介紹了Kotlin的條件式if、when
if (a > b) {
max = a
} else {
max = b
}
when (x) {
1 -> print("x == 1")
2 -> print("x == 2")
else -> {
print("x is neither 1 nor 2")
}
}
接著我們繼續談for迴圈、while迴圈以及do-while迴圈
for (i in 1..3) {
println(i)
}
while (x > 0) {
x--
}
do {
val y = retrieveData()
} while (y != null)